<?php
namespace app\shouyin\model;

use think\Model;
use app\shouyin\model\UserCardLog as UserCardLogModel;
use app\shouyin\model\UserBalanceLog as UserBalanceLogModel;
use app\shouyin\model\SubscribeProject as SubscribeProjectModel;
use app\finance\model\SystemBalanceLog as SystemBalanceLogModel;
use app\user\model\User as UserModel;
class Subscribe extends Model
{
    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    // 自动写入时间戳
    protected $autoWriteTimestamp = true;


    public function setProjectIdsAttr($value,$data)
    {
        return implode(',',$data['project_ids']);
    }
    public function setTechnicianIdsAttr($value,$data)
    {
        return implode(',',$data['technician_ids']);
    }
    public function getProjectIdsAttr($value)
    {

        return explode(',',$value);
    }
    public function getTechnicianIdsAttr($value)
    {
        if(empty($value)){
            return [];
        }
        return explode(',',$value);
    }
    public function hasShop()
    {
        return $this->hasOne('app\shop\model\Shop', 'id', 'shop_id');
    }
    public function getUserNameAttr($value)
    {
        $name = UserModel::where('id',$value)->value('nick');
        return $name;
    }
    public function hasUser()
    {
        return $this->hasOne('app\user\model\User', 'id', 'user_id');
    }
    public function hasRoom()
    {
        return $this->hasOne('app\shop\model\Room', 'id', 'room_id');
    }
}
